Functions

A <#64#>function<#64#> is a mathematical object that takes in an argument (which could well be another function) and returns some other mathematical object. For example the function Not takes in a boolean and returns its complement. I'll write function application without brackets, so Not~b is the boolean complement of b.

Function application binds to the left, so f~a~b is (f~a)~b rather than f~(a~b). For example, Or~a~b is the boolean or of a and b, and Or~True is a perfectly good function that takes in a boolean and returns True.

The obvious equivalents of functions in TEX are macros --- if I define a function Foo to be:

#math83#
Foo~x = True  

then it can be translated into TEX as:
verbatim67#
So where Foo is a function that takes in one argument, 8 is a macro that takes in one parameter. Nothing has changed except the jargon and the font. TEX macros can even be partially applied, for example if we defined:
#math84#
Baz = Or~True  

then the TEX equivalent would be
verbatim68#
Once 9 is expanded, it will expect to be given a parameter, but when we are defining things, we can go around partially applying them all we like.

Here, I'm using = without formally defining it, which is rather naughty. If I say x = y, this means ``given enough parameters, x and y will eventually expand out to the same thing.'' For example Foo = Baz, because for any x,

#math85#
Foo~x;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp;
  = True  
  = Or~True~x  
  = Baz~x  

Normally, functions have to <#76#>respect equality<#76#> which means that:
  • if x = y then f~x = f~y, and
  • if x respects equality, then f~x respects equality.
However, some TEX control sequences don't obey this. For example, 10 and 11 are different, even though Foo = Baz. Hence string doesn't respect equality. Unless otherwise stated, we won't assume functions respect equality, although all the functions defined here do.

All of our functions have capital letters, so that their TEX equivalents (12, 13 and so on) don't clash with standard TEX or LATEX macros.